<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/1.2.1/axios.js"></script>
</head>

<body>
    <ul class="list">
       
    </ul>
    <button>获取电影</button>
    <button>添加电影</button>
    <button>修改电影</button>
    <button>局部修改</button>
    <button>删除电影</button>
    <script>
       let btns = document.querySelectorAll('button');
       let ul = document.querySelector('ul');
       btns[0].onclick = function(){
          // url    // get
          axios('http://localhost:3000/movies').then(({data})=>{
            //  config 配置对象
            //  data 数据
            //  headers 请求头对象
            //  request XHR请求对象
            //  status 响应状态码
            //  statusText 响应状态说明
            console.log(data);
            let str = data.map(({name})=>`<li>${name}</li>`).join('');
            ul.innerHTML = str;
          }) 
       }
       
       btns[1].onclick = function(){
         axios('http://localhost:3000/movies',{
             method:"POST",
             data:{
                name:"生化危机",
                director:"银河护卫队",
                star:"爱丽丝"
             }
         }).then(val=>{
             console.log(val);
         })
       }

       btns[4].onclick = async function(){
           let lis = document.querySelectorAll('ul li');

           let res = await axios(`http://localhost:3000/movies/${lis.length}`,{
               method:"delete"
           });


           btns[0].onclick();
           console.log(res);
       }
    </script>
</body>

</html>